/**
 * Copyright (C), 2019-2020, 宇信融汇
 * FileName: HashMapTest
 * Author:   666
 * Date:     2020/7/20 22:04
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 666           修改时间           版本号              描述
 */
package c_009.map;

import org.junit.Test;

import java.util.*;

/**
 * @Classname HashMapTest
 * @Description TODO
 * @Date 2020/7/20 22:04
 * @Created by 666
 */
public class HashMapTest {
    @Test
    public void hashMapTest() {
        HashMap map = new HashMap();
        map = new LinkedHashMap<>();
        map.put(111, "aaa");
        map.put(222, "bbb");
        map.put(333, "ccc");
        System.out.println(map);
    }

    @Test
    public void test1() {
        HashMap map = new HashMap();
        map.put(123, "aa");
        map.put(45, "aa");
        map.put("aa", 2314);
        System.out.println(map.size());
        map.clear();
        System.out.println(map.isEmpty());
        System.out.println(map.size());

    }

    //map的遍历操作
    @Test
    public void test2() {
        HashMap map = new HashMap();
        map.put(123, "354");
        map.put(45, "aa");
        map.put("aa", 2314);
        Set keySet = map.keySet();
        Iterator iterator = keySet.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }

        System.out.println("-------------------------------------");
        Collection values = map.values();
        Iterator iterator1 = values.iterator();
        while (iterator1.hasNext()) {
            System.out.println(iterator1.next());
        }
        System.out.println("-------------------------------------");
        for (Object obj : values) {
            System.out.println(obj);
        }
        System.out.println("-------------------------------------");
        Set enTrySet = map.entrySet();
        Iterator iterator2 = enTrySet.iterator();
        while (iterator2.hasNext()){
            Object o = iterator2.next();
            Map.Entry a = (Map.Entry) o;
            System.out.println(a.getKey()+"--------------"+a.getValue());

        }


    }
}
